package com.justreading.netty.protobuf.codec;

import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

/**
 * @author LYJ
 * @Description
 * @date 2021 年 11 月 06 日 下午6:55
 */
public class NettyServerHandler extends SimpleChannelInboundHandler<StudentPOJO.Student> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, StudentPOJO.Student msg) throws Exception {
        System.out.println("客户端发送的数据: +" + msg.getName());
        StudentPOJO.Student student = StudentPOJO.Student.newBuilder().setName("服务端收到，我是吴用").build();
        ctx.channel().write(student);
//        ctx.channel().writeAndFlush(Unpooled.copiedBuffer(student.toByteArray()));
    }


    @Override
    public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {

    }
}
